import { http } from "@/utils/http";

export type UserResult = {
  code: number;
  data: {
    /** 用户名 */
    username: string;
    /** 当前登陆用户的角色 */
    roles: Array<string>;
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: number;
  };
};

export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: number;
  };
};


export type UserListResult = {
  code: number;
  data: {
    count: number;
    data: [
      {
        id: string;
        phone: string;
        account: string;
        email: string;
        type: number;
        isEnable:Boolean;
        createTime: Date;
        updateTime: Date;
      }
    ]
  };
  msg: string;
};

export type Result = {
  code: number;
  data: any;
  msg:string;
};

/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<UserResult>("post", "/api/auth/admin/login", { data });
};

/** 刷新token */
export const refreshTokenApi = (data?: object) => {
  return http.request<RefreshTokenResult>("post", "/refreshToken", { data });
};

export const getUserList = (params?: object) => {
  return http.request<UserListResult>("get", "/api/system/user/list", { params });
};
export const update = (data?: object) => {
  return http.request<Result>("put", "/api/system/user/update", { data });
};
export const addUser = (data?: object) => {
  return http.request<Result>("post", "/api/system/user/add", { data });
};
export const deleteUser = (params?: object) => {
  return http.request<Result>("delete", "/api/system/user/"+  params );
};
